package org.opens.javaskill.design;

public class DecoratorPattern {

    public static void main(String[] args) {
        KnowledgeSearch knowledgeSearch = new KnowledgeSearch();
        BusinessSearch businessSearch = new BusinessSearch();

        LoadQueryParamsSearch loadQueryParamsBusinessSearch = new LoadQueryParamsSearch(new BusinessSearch());
        LoadQueryParamsSearch loadQueryParamsKnowledgeSearch = new LoadQueryParamsSearch(new KnowledgeSearch());

        knowledgeSearch.search();
        businessSearch.search();
        loadQueryParamsBusinessSearch.search();
        loadQueryParamsKnowledgeSearch.search();
    }

}

interface SearchData {

    void search();

}

class KnowledgeSearch implements SearchData {

    @Override
    public void search() {
        System.out.println("搜索知识数据.");
    }

}

class BusinessSearch implements SearchData {

    @Override
    public void search() {
        System.out.println("搜索业务数据.");
    }

}

abstract class SearchDecorator implements SearchData {

    protected SearchData searchData;

    public SearchDecorator(SearchData searchData) {
        this.searchData = searchData;
    }

    @Override
    public void search() {
        searchData.search();
    }

}

class LoadQueryParamsSearch extends SearchDecorator {

    public LoadQueryParamsSearch(SearchData searchData) {
        super(searchData);
    }

    public void loadQueryParams() {
        System.out.println("加载搜索参数.");
    }

    @Override
    public void search() {
        this.loadQueryParams();
        super.search();
    }
}
